package com.qcxy.gzy.activity.base;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.qcxy.gzy.activity.R;
import com.qcxy.gzy.activity.base.HiddenActivity;

public class TotalActivity extends HiddenActivity implements OnClickListener, OnSeekBarChangeListener, OnTouchListener {

    protected SeekBar mSeekBar;
    protected TextView mTargetValue;
    protected TextView mTargetNumber;
    protected TextView mUnit;
    
    protected int mTarget = 0;
    protected Timer timer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_total);
		
		findViewById(R.id.iv_back).setOnClickListener(this);
		mSeekBar = (SeekBar) findViewById(R.id.sb_target);
		mTargetValue = (TextView) findViewById(R.id.tv_target);
		mTargetNumber = (TextView) findViewById(R.id.tv_target_number);
		mUnit = (TextView) findViewById(R.id.tv_target_unit);
		findViewById(R.id.iv_target_reduce).setOnClickListener(this);
		findViewById(R.id.iv_target_plus).setOnClickListener(this);
		findViewById(R.id.iv_target_reduce).setOnTouchListener(this);
		findViewById(R.id.iv_target_plus).setOnTouchListener(this);
		findViewById(R.id.ll_go).setOnClickListener(this);
		mSeekBar.setOnSeekBarChangeListener(this);
		
	}

	@Override
	public void onClick(View v) {
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
		// TODO Auto-generated method stub
		mTarget = progress;
		mTargetValue.setText(String.valueOf(progress));
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		return false;
	}
	
	public class TimeTask extends TimerTask {
		private int type;
		public TimeTask(int type) {
			// TODO Auto-generated constructor stub
			this.type = type;
			
		}

		@Override
		public void run() {
			// TODO Auto-generated method stub
			Message message = new Message();
			if(type ==1){
				message.what = type;
			}else if(type == 2){
				message.what = type;
			}else if(type == 3){
				message.what = type;
			}else{
				message.what = type;
			}
			mHandler.sendMessage(message);
		}	
	}
	
	public Handler mHandler = new Handler() {
		// 接收到消息后处理
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case 1:
				if(mTarget > 0){
					mTarget --;
					mTargetValue.setText(String.valueOf(mTarget));
					mSeekBar.setProgress(mTarget);
				}
				break;
			case 2:
				if(mTarget < 100){
					mTarget ++;
					mTargetValue.setText(String.valueOf(mTarget));
					mSeekBar.setProgress(mTarget);
				}
				break;
			case 3:
				if(mTarget < 60){
					mTarget ++;
					mTargetValue.setText(String.valueOf(mTarget));
					mSeekBar.setProgress(mTarget);
				}
				break;
			case 4:
				if(mTarget < 200){
					mTarget ++;
					mTargetValue.setText(String.valueOf(mTarget));
					mSeekBar.setProgress(mTarget);
				}
				break;
			}
		}
	};
}
